package logic

import (
	"context"
	"fmt"
	"shop_srv/cache"
	"shop_srv/internal/svc"
	"shop_srv/shop"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartListLogic {
	return &CartListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartListLogic) CartList(in *shop.CartListRequest) (*shop.CartListResponse, error) {
	// todo: add your logic here and delete this line

	key := fmt.Sprintf("cart_%d_*", in.UserId)
	keys := cache.Rdb.Keys(context.Background(), key).Val()

	if len(keys) == 0 {
		return &shop.CartListResponse{}, nil
	}

	//var listcaet []*shop.CartList
	//for _, s := range keys {
	//	goodsMap, _ := cache.Rdb.HGetAll(context.Background(), s).Result()
	//
	//	goodsId, _ := strconv.Atoi(goodsMap["goods_id"])
	//	num, _ := strconv.Atoi(goodsMap["num"])
	//
	//}

	return &shop.CartListResponse{}, nil
}
